//
//  AppDelegate.m
//  NBA
//
//  Created by Jaedong on 2018/3/9.
//  Copyright © 2018年 Jaedong. All rights reserved.
//

#import "AppDelegate.h"
#import "NBAPopoverViewController.h"
#import "NBAMenu.h"

@interface AppDelegate ()<NSMenuDelegate>

@property (nonatomic, strong) NSStatusItem *statusItem;

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    [self p_addStatusItem];
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

# pragma mark - Functions
- (void)p_addStatusItem{
    //获取系统单例NSStatusBar对象
    NSStatusBar *statusBar = [NSStatusBar systemStatusBar];
    
    NSStatusItem *statusItem = [statusBar statusItemWithLength: NSSquareStatusItemLength];
    self.statusItem = statusItem;
    [statusItem setHighlightMode:YES];
    [statusItem setImage: [NSImage imageNamed:@"N"]]; //设置图标，请注意尺寸
    [statusItem setToolTip:@"点击查看比分情况"];
    [statusItem setLength:40];
    [statusItem setTarget:self];

    NBAMenu *subMenu = [[NBAMenu alloc] initWithTitle:@"NBA"];
    statusItem.menu = subMenu;
    subMenu.delegate = self;
}

- (void)menuWillOpen:(NSMenu *)menu {
    NBAMenu *nbaMenu = (NBAMenu *)menu;
    [nbaMenu refreshScore];
}

@end
